SELECT ?country ?population ?capital
WHERE {
?country a dbo:Country .
?country dbp:populationTotal ?population .
?country dbo:capital ?capital_URI .
?capital_URI rdfs:label ?capital .
}
#Query #DBpediaPREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
SELECT *
WHERE {
?s skosxl:prefLabel ?Label_URI .
?Label_URI skosxl:literalForm ?label .
FILTER (LANG(?label) = "es")
}
SELECT (COUNT (?work_of_Agatha_Christie) AS ?Number_of_AC_works)
{?work_of_Agatha_Christie dbo:author dbr:Agatha_Christie }
#Query #COUNTSELECT DISTINCT ?property
WHERE {
?s ?property ?o .
FILTER (STRSTARTS(STR(?property), "http://www.w3.org/2004/02/skos/core#" ))
}
#Query #STRSTARTSSELECT DISTINCT ?class
WHERE {
?work dbo:author ?author .
?work a ?class .
FILTER (STRSTARTS(STR(?class),"http://dbpedia.org/ontology/" ))
}
#Query #STRSTARTS #DBpediaNOT EXISTS - Testing for absence of a pattern (recommended in most cases)MINUS - Removing possible solutions!BOUND - Not bound (produces the same results as NOT EXISTS but works also for SPARQL 1.0)NOT EXISTS and MINUS have different logic and may produce different results on the same dataset.
#+END_IMPORTANTSELECT ?work
WHERE {
?work a dbo:Artwork .
?work dbo:museum dbr:Louvre .
FILTER NOT EXISTS {?work dbo:author ?artist .}
}
#Query #FILTER #[[NOT EXISTS]]PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?Influenced
WHERE {
{ ?Influenced dbo:influencedBy dbr:Ludwig_Wittgenstein.}
UNION
{ dbr:Ludwig_Wittgenstein dbo:influenced ?Influenced .}
}
#Query #UNIONSELECT DISTINCT ?MusicalWork ?Artist
WHERE {
?MusicalWorkURI a dbo:MusicalWork ;
rdfs:label ?MusicalWork ;
dbo:artist ?ArtistURI .
?ArtistURI rdfs:label ?Artist .
FILTER (lang(?MusicalWork) = "en")
FILTER (lang(?Artist) = "en")
FILTER REGEX (?MusicalWork, "broken", "i")
}
ORDER BY ?MusicalWork
#Query #REGEX #FILTER #LANG #[[ORDER BY]]PREFIX cdm: <http://publications.europa.eu/ontology/cdm#>
SELECT ?reg (IRI(CONCAT(STR(?eli),"/eng/pdf")) AS ?pdf_URL)
{
?reg cdm:resource_legal_eli ?eli .
}
LIMIT 1000
#Query #IRI #CONCAT #Cellar#Inverse Path:
^:property #Inverse path (object to subject)
#Sequence Path:
:property1/:property2 #A sequence path of :property1 followed by :property2
#Alternative Path:
:property1|:property2 #:property1 or property2 (all possibilities are tried)
#Zero Or More:
:property* #A path that connects the subject and object of the path by zero or more matches of :property
#One Or More:
:property+ #A path that connects the subject and object of the path by one or more matches of :property
#Zero Or One Path:
:property? #A path that connects the subject and object of the path by zero or one matches of :property
SELECT (COUNT (DISTINCT ?child) AS ?Number_of_children)
{
?MS a dbo:Country;
dct:subject dbc:Member_states_of_the_European_Union ;
dbp:leaderName ?leader .
?leader dbo:child|^dbo:parent ?child.
#Works the same as
# {?leader dbo:child ?child.}
# UNION
# {?child dbo:parent ?leader}
}
#Query #| #^ #UNIONSELECT
(COUNT (DISTINCT ?Influencer) AS ?Num_Influencer)
(COUNT (DISTINCT ?Influenced) AS ?Num_Influenced)
WHERE {
{dbr:Ludwig_Wittgenstein dbo:influencedBy|^dbo:influenced ?Influencer .}
UNION
{dbr:Ludwig_Wittgenstein dbo:influenced|^dbo:influencedBy ?Influenced .}
}
#Query #DBpedia #| #^ #COUNT #UNIONFILTER (LANG(?label) = "fr") will only return results where the language tag of ?label is @fr, while FILTER langMATCHES( LANG(?label), "fr" ) will also include those with regions such as @fr-BE.
Adding "Label" to a variable will get the label of the respective item if the Wikidata Label service is called in the query. For example, for ?item, ?itemLabel will get the labels in the selected language.
SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language “en" }
}
#+BEGIN_TIP To include a call to the Label Service in your query, just press Ctrl-Space and start typing "label" until you see the query fragment. Then change the language if needed.
Check the Label service manual for other capabilities. #+END_TIP
?statement variable <iframe src="https://w.wiki/4wNL" <button class="pull-url autopull" value="https://w.wiki/4wNL"">pull style="width:100%;max-width:100%;height:450px" frameborder="0">
#Query #Wikidata #Qualifiers# Example with a block of values, where the third block in the list has no value for ?v2
VALUES (?v1 ?v2) {(:c11 :c21) (:c21 :c22) (:c21 UNDEF)}
# When value for only one variable are provided, () can be omitted
VALUES ?v1 {:c1 :c2 :c3 :cN}
#VALUES(GROUP_CONCAT (?V; SEPARATOR = ", ") AS ?groupV)
#GROUP_CONCATASK WHERE {...}